/**
 * copyright (C) geolabs 2006-2007
 * author : Gérald Fenoy gerald [ at ] geolabs [dot] fr
 *
 */

HTMLEntity=Class.create({
  encode: function(s){
      var result = '';
      for (var i = 0; i < s.length; i++){
	var c = s.charAt(i);
	result += {'<':'&lt;', '>':'&gt;', '&':'&amp;', '"':'&quot;', "'":'@#34;'}[c] || c;
      }
      return result;
    },
  decode: function(s){
      var result = '';
      for (var i = 0; i < s.length; i++){
	var c = s.charAt(i);
	if(c=="&"){
	  var initial=i;
	  for(i=i+1;s.charAt(i)!=";" && i-initial<10;i++){
	    c+=s.charAt(i);
	  }
	  if(i-initial==10){
	    i=initial;
	    c=s.charAt(i);
	  }
	  else
	    c+=s.charAt(i);
	}
	result += { '&reg;': '®', '&trade;': '™', '&':'&amp;', '&lt;':'<', '&gt;':'>', '&quot;':'"', '&#34;':"'", '&#39;':"'", '&#8217;':'\'\'', '&mdash;': '#'}[c] || c;
      }
      return result;
    }
  });
